package runner

import (
	"github.com/gogf/gf/crypto/gaes"
	"github.com/gogf/gf/os/gmlock"
	"github.com/gogf/gf/os/gproc"
)

//RunShell 阻塞执行shell指令，并返回输出结果(如果需要异步，请使用goroutine)
func RunShell(args, cloneUrl string) (string, error) {
	gmlock.Lock(cloneUrl)
	out, err := gproc.ShellExec("set -e;" + args)
	gmlock.Unlock(cloneUrl)
	return out, err
}

var aesKey = "x123456789x123456789x123456789x1"

//EnCrypt Aes 加密git密码
func EnCrypt(plainText string) (string, error) {
	res, err := gaes.Encrypt([]byte(plainText), []byte(aesKey))
	if err != nil {
		return "", err
	}
	return string(res), nil
}

//DeCrypt Aes 解密git密码
func DeCrypt(cipherText string) (string, error) {
	res, err := gaes.Decrypt([]byte(cipherText), []byte(aesKey))
	if err != nil {
		return "", err
	}
	return string(res), nil
}
